package com.zxy.ziems.server.budget.controller;

import com.zxy.btp.common.response.JsonResponse;
import com.zxy.btp.common.response.PageResult;
import com.zxy.ziems.server.budget.pojo.dto.BudgetDefDTO;
import com.zxy.ziems.server.budget.pojo.param.BudgetDefParam;
import com.zxy.ziems.server.budget.pojo.vo.BudgetManagerVO;
import com.zxy.ziems.server.budget.service.BudgetDefService;
import com.zxy.ziems.server.budget.service.BudgetValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预算管理
 */
@RestController
@RequestMapping("/api/budget/manager")
public class BudgetManagerController {

    @Autowired
    private BudgetDefService budgetDefService;
    @Autowired
    private BudgetValueService budgetValueService;

    /**
     * 新增预算标签
     * @param budgetDefDTOs
     * @return
     */
    @PostMapping("/addDef")
    public JsonResponse<Void> addDef(@Validated(BudgetDefDTO.Add.class) @RequestBody List<BudgetDefDTO> budgetDefDTOs) {
        budgetDefService.adds(budgetDefDTOs);
        return JsonResponse.SUCCESS();
    }

    /**
     * 批量删除预算标签
     * @param ids
     * @return
     */
    @DeleteMapping("/remove")
    public JsonResponse<Void> remove(@RequestParam("ids") List<String> ids) {
        budgetDefService.remove(ids);
        return JsonResponse.SUCCESS();
    }

    /**
     * 分页查看预算
     * @param param
     * @return
     */
    @GetMapping("/page")
    public PageResult<BudgetManagerVO> page(@Validated BudgetDefParam param) {
        return budgetDefService.page(param);
    }

    /**
     * 新增/修改预算数值
     * @param budgetDefDTO
     * @return
     */
    @PostMapping("/addValue")
    public JsonResponse<Void> addValue(@Validated(BudgetDefDTO.AddVal.class) @RequestBody BudgetDefDTO budgetDefDTO) {
        budgetValueService.add(budgetDefDTO);
        return JsonResponse.SUCCESS();
    }
}
